package com.ruoyi.eam.service.impl;

import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.eam.doman.DictData;
import com.ruoyi.eam.doman.EamAsset;
import com.ruoyi.eam.doman.EamStockD;
import com.ruoyi.eam.doman.EamType;
import com.ruoyi.eam.doman.vo.EamAssetVo;
import com.ruoyi.eam.mapper.*;
import com.ruoyi.eam.service.IEamAssetService;
import io.swagger.models.auth.In;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * 固定资产Service业务层处理
 *
 * @author ruoyi
 * @date 2024-06-17
 */
@Service
public class EamAssetServiceImpl implements IEamAssetService
{
    @Resource
    private EamAssetMapper eamAssetMapper;

    @Resource
    private EamTypeMapper eamTypeMapper;

    @Resource
    private EamStockMapper eamStockMapper;

    @Resource
    private DictDataMapper dictDataMapper;

    /**
     * 查询固定资产
     *
     * @param assetId 固定资产主键
     * @return 固定资产
     */
    @Override
    public EamAsset selectEamAssetByAssetId(Long assetId)
    {
        return eamAssetMapper.selectEamAssetByAssetId(assetId);
    }

    @Override
    public List<EamAsset> selectEamAssetId(Long assetId) {
        List<EamAsset>list= eamAssetMapper.selectEamAssetId(assetId);
        return list;
    }

    /**
     * 查询固定资产列表
     *
     * @param eamAsset 固定资产
     * @return 固定资产
     */
    @Override
    public List<EamAsset> selectEamAssetList(EamAsset eamAsset)
    {
        List<EamAsset>list=eamAssetMapper.selectEamAssetList(eamAsset);
        for (EamAsset asset : list) {
            if(asset != null){
                EamType eamType = eamTypeMapper.selectEamTypeByTypeId(asset.getTypeId());
                asset.setNum(eamAssetMapper.selectEamAssetCount(asset.getAssetId()));
                asset.setEamType(eamType);
            }
        }
        return list;
    }

    @Override
    public List<EamAsset> queryEamDateList(EamAsset eamAsset)
    {
        List<EamAsset> list = eamAssetMapper.queryEamAssetList();
        System.out.println(list);
        List<EamAsset> list1 = new ArrayList<>();
        for (EamAsset asset : list) {
            if(asset != null){
                Integer num =  eamAssetMapper.selectEamAssetCount(asset.getAssetId());
                System.out.println("num"+num);
                if(num > 0){
                    asset.setNum(num);
                    list1.add(asset);
                }
            }
        }
        return list1;
    }

    @Override
    public List<Integer> selectEamAssetCount() {
        List<EamAsset> eamAssets = eamAssetMapper.selectEamAssetList(new EamAsset());
        List<Integer> integerList = new ArrayList<>();
        for (EamAsset asset : eamAssets) {
            Integer num = eamAssetMapper.selectEamAssetCount(asset.getAssetId());
            integerList.add(num);
        }
        return  integerList;
    }

    @Override
    public int selectEamAssetUseStatus(Long useStatus) {
        return eamAssetMapper.selectEamAssetUseStatus(useStatus);
    }

    @Override
    public int selectEamAssetCounts() {
        return eamAssetMapper.selectEamAssetCounts();
    }

    @Override
    public int selectEamAssetPriceSum() {
        return eamAssetMapper.selectEamAssetPriceSum();
    }


    @Override
    public List<EamAsset> selectEamAssetByuseStatus(EamAsset eamAsset) {
        List<EamAsset>list = eamAssetMapper.selectEamAssetByuseStatus(eamAsset);
        List<EamAsset> filteredList = new ArrayList<>();
        for (EamAsset asset : list) {
            System.out.println(asset.getAssetName());
            if(asset != null){
                EamType eamType = eamTypeMapper.selectEamTypeByTypeId(asset.getTypeId());
                asset.setEamType(eamType);
                int num = eamStockMapper.assetIsStock(asset.getAssetId());
                if(num == 1){
                    continue;
                }
                filteredList.add(asset);
            }
        }
        return filteredList;
    }

    @Override
    public List<EamAsset> getListAll(EamAsset asset) {
        List<EamAsset> list = eamAssetMapper.selectEamAssetList(asset);
        for (EamAsset eamAsset : list) {
            eamAsset.setDictData(dictDataMapper.selectDictDataByDictCode(eamAsset.getUseStatus()));
            eamAsset.setEamType(eamTypeMapper.selectEamTypeByTypeId(eamAsset.getTypeId()));
        }
        return list;
    }

    /**
     * 新增固定资产
     *
     * @param eamAsset 固定资产
     * @return 结果
     */
    @Override
    public int insertEamAsset(EamAsset eamAsset)
    {
        eamAsset.setCreateTime(DateUtils.getNowDate());
        return eamAssetMapper.insertEamAsset(eamAsset);
    }

    /**
     * 修改固定资产
     *
     * @param eamAsset 固定资产
     * @return 结果
     */
    @Override
    public int updateEamAsset(EamAsset eamAsset)
    {
        return eamAssetMapper.updateEamAsset(eamAsset);
    }

    /**
     * 批量删除固定资产
     *
     * @param assetIds 需要删除的固定资产主键
     * @return 结果
     */
    @Override
    public int deleteEamAssetByAssetIds(Long[] assetIds)
    {
        return eamAssetMapper.deleteEamAssetByAssetIds(assetIds);
    }

    /**
     * 删除固定资产信息
     *
     * @param assetId 固定资产主键
     * @return 结果
     */
    @Override
    public int deleteEamAssetByAssetId(Long assetId)
    {
        return eamAssetMapper.deleteEamAssetByAssetId(assetId);
    }

    @Override
    public int queryTypeList(Long useStatus) {
        return eamAssetMapper.queryTypeList(useStatus);
    }
}
